package com.nlx.notes.module.core.util;

import java.util.Random;

public class DataUtils {

    /**
     * 生成指定长度的随机数
     * @param length 长度
     * @return String
     */
    public static String generateCode(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("验证码长度必须大于0");
        }

        Random random = new Random();
        StringBuilder code = new StringBuilder();

        for (int i = 0; i < length; i++) {
            code.append(random.nextInt(10));  // 每次追加 0-9 的数字
        }
        return code.toString();
    }

    public static String genUserCode(){
        String userCode = UUIDUtils.genUUId();
        return userCode.replaceAll("-","");
    }


}
